package com.rapid.maintenance.adapter;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.Utils;
import com.chad.library.adapter.base.BaseViewHolder;
import com.rapid.maintenance.R;
import com.rapid.maintenance.base.BaseAdapter;

/**
 *
 */
public class SimpleSliderAdapter extends BaseAdapter<String> {
    private String selected;
    private Utils.Callback<String> onSelectCallBack;

    public SimpleSliderAdapter() {
        super(R.layout.item_simple_slider);
        setOnItemClickListener((adapter, view, position) -> {
            selected = getItem(position);
            if (onSelectCallBack != null) onSelectCallBack.onCall(selected);
            notifyDataSetChanged();
        });
    }

    public void setOnSelectCallBack(Utils.Callback<String> onSelectCallBack) {
        this.onSelectCallBack = onSelectCallBack;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, String item) {
        helper.setText(R.id.text, item);
        helper.itemView.setSelected(item.equals(selected));
    }
}
